/**
 * 线索实体类
 * 定义AI侦探应用中的线索数据结构
 */
export class Clue {
  // 线索ID
  id: string;
  
  // 线索标题
  title: string;
  
  // 线索描述
  description: string;
  
  // 所属案件ID
  caseId: string;
  
  // 发现者ID
  discovererId: string;
  
  // 发现时间
  discoveredAt: Date;
  
  // 重要程度
  importance: 'low' | 'medium' | 'high' | 'critical';
  
  // 线索状态
  status: 'pending' | 'verified' | 'rejected';
  
  // 相关人员ID
  relatedPersonId?: string;
  
  // 相关证据ID
  relatedEvidenceId?: string;
  
  // 线索类型
  clueType: string;
  
  // 线索位置
  location?: string;
  
  // 备注
  notes?: string;
  
  // AI分析结果
  aiAnalysis?: {
    relevanceScore: number;
    analysisNotes: string;
    potentialLinks: string[];
  };
  
  /**
   * 构造函数
   * @param clueData 线索数据
   */
  constructor(clueData: {
    id?: string;
    title: string;
    description: string;
    caseId: string;
    discovererId: string;
    discoveredAt?: Date;
    importance?: 'low' | 'medium' | 'high' | 'critical';
    status?: 'pending' | 'verified' | 'rejected';
    relatedPersonId?: string;
    relatedEvidenceId?: string;
    clueType: string;
    location?: string;
    notes?: string;
    aiAnalysis?: {
      relevanceScore: number;
      analysisNotes: string;
      potentialLinks: string[];
    };
  }) {
    this.id = clueData.id || this.generateId();
    this.title = clueData.title;
    this.description = clueData.description;
    this.caseId = clueData.caseId;
    this.discovererId = clueData.discovererId;
    this.discoveredAt = clueData.discoveredAt || new Date();
    this.importance = clueData.importance || 'medium';
    this.status = clueData.status || 'pending';
    this.relatedPersonId = clueData.relatedPersonId;
    this.relatedEvidenceId = clueData.relatedEvidenceId;
    this.clueType = clueData.clueType;
    this.location = clueData.location;
    this.notes = clueData.notes;
    this.aiAnalysis = clueData.aiAnalysis;
  }
  
  /**
   * 生成唯一ID
   * @returns 唯一ID字符串
   */
  private generateId(): string {
    return `clue_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
  }
  
  /**
   * 更新线索状态
   * @param status 新状态
   */
  updateStatus(status: 'pending' | 'verified' | 'rejected'): void {
    this.status = status;
  }
  
  /**
   * 设置AI分析结果
   * @param analysis AI分析结果
   */
  setAiAnalysis(analysis: {
    relevanceScore: number;
    analysisNotes: string;
    potentialLinks: string[];
  }): void {
    this.aiAnalysis = analysis;
  }
  
  /**
   * 转换为JSON对象
   * @returns JSON格式的线索数据
   */
  toJSON() {
    return {
      id: this.id,
      title: this.title,
      description: this.description,
      caseId: this.caseId,
      discovererId: this.discovererId,
      discoveredAt: this.discoveredAt.toISOString(),
      importance: this.importance,
      status: this.status,
      relatedPersonId: this.relatedPersonId,
      relatedEvidenceId: this.relatedEvidenceId,
      clueType: this.clueType,
      location: this.location,
      notes: this.notes,
      aiAnalysis: this.aiAnalysis
    };
  }
  
  /**
   * 从JSON对象创建Clue实例
   * @param json JSON格式的线索数据
   * @returns Clue实例
   */
  static fromJSON(json: any): Clue {
    return new Clue({
      id: json.id,
      title: json.title,
      description: json.description,
      caseId: json.caseId,
      discovererId: json.discovererId,
      discoveredAt: json.discoveredAt ? new Date(json.discoveredAt) : new Date(),
      importance: json.importance,
      status: json.status,
      relatedPersonId: json.relatedPersonId,
      relatedEvidenceId: json.relatedEvidenceId,
      clueType: json.clueType,
      location: json.location,
      notes: json.notes,
      aiAnalysis: json.aiAnalysis
    });
  }
}